<template>
  <div class="home">
    <el-container>
      <el-header>
        <el-row>
          <el-col :span="3"><div>公司Logo</div></el-col>
          <el-col :span="18"><div>电商后台管理系统</div></el-col>
          <el-col :span="3"><button @click="quit">退出</button></el-col>
        </el-row>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '60px' : '200px'">
          <div @click="isCollapse = !isCollapse">|||</div>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :collapse="isCollapse"
            :collapse-transition="false"
            :unique-opened="true"
            router
          >
            <el-submenu
              :index="item.id + ''"
              v-for="item in menu"
              :key="item.id"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  :index="item1.path"
                  v-for="item1 in item.children"
                  :key="item1.id"
                  >{{ item1.authName }}</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main> <router-view></router-view></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { getMenusApi } from "@/http/api";
export default {
  name: "home",
  data() {
    return {
      //侧栏展收开关
      isCollapse: false,
      menu: [],
    };
  },
  computed: {},
  methods: {
    //左侧栏数据
    async getMenus() {
      const res = await getMenusApi();
      console.log(res, "左侧栏数据");
      this.menu = res;
    },

    //退出清除本地,跳转Login页
    quit() {
      sessionStorage.removeItem("token");
      this.$router.push("/login");
    },
  },
  mounted() {},
  created() {
    this.getMenus();
  },
};
</script>
<style scoped lang="scss">
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  height: 92vh;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  height: 192vh;
}
</style>
